//
//  Adpator.KeyWindow.swift
//  Adaptor
//
//  Created by 蒋晨成 on 2021/12/23.
//

import UIKit

public extension Adaptor { enum KeyWindow {} }

public extension Adaptor.KeyWindow {
    static let scene: UIWindowScene = {
        guard let scene = UIApplication.shared.connectedScenes
            .filter({ $0.activationState == .foregroundActive })
            .map({ $0 as? UIWindowScene })
            .compactMap({ $0 })
            .first
        else { fatalError("key window scene not found") }
        return scene
    }()
}

private extension Adaptor.KeyWindow {
    static let current: UIWindow = {
        guard let keyWindow = scene.windows
            .filter(\.isKeyWindow).first
        else { fatalError("key window not found") }
        return keyWindow
    }()
}

public extension Adaptor.KeyWindow {
    static let safeAreaTop = current.safeAreaInsets.top
    static let safeAreaBottom = current.safeAreaInsets.bottom
}
